<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	template="/WEB-INF/layout/t.xhtml">

	<ui:define name="title">
		<h:outputText value="Amministrazione del portale" />
	</ui:define>
	<ui:define name="roles">
		<f:attribute name="roles" value="news" />
	</ui:define>
	<ui:define name="content">
		<script type="text/javascript"
			src="#{request.contextPath}/js/it_editor.js"></script>
		<script type="text/javascript">
         //<![CDATA[
function addImageBrowser() {
            myEditor.on('toolbarLoaded', function() {
    //When the toolbar is loaded, add a listener to the insertimage button
    this.toolbar.on('insertimageClick', function() {
        //Get the selected element
        var _sel = this._getSelectedElement();
        //If the selected element is an image, do the normal thing so they can manipulate the image
        if (_sel && _sel.tagName && (_sel.tagName.toLowerCase() == 'img')) {
            //Do the normal thing here..
        } else {
            //They don't have a selected image, open the image browser window
            win = window.open('#{request.contextPath}/private/gallerie/images.jsf', 'IMAGE_BROWSER',
                'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,status=0');
            if (!win) {
                //Catch the popup blocker
                alert('Please disable your popup blocker!!');
            }
            //This is important.. Return false here to not fire the rest of the listeners
            return false;
        }
    }, this, true);
}, myEditor, true);

         }

          window.onload = addImageBrowser;
         //]]>
      </script>

		<h:form prependId="false">

			<p:messages id="messages" />
			<center>
				<p:panel header="Gestione Notizia">

					<h:panelGrid columns="2" style="width: 95%">
						<h:outputLabel for="titolo" value="Titolo" />
						<h:inputText id="titolo" value="#{newsController.element.title}"
							style="width: 100%;" required="true" />


						<h:outputLabel value="Tipo informazione(*):" for="tipo" />
						<h:selectOneMenu id="tipo" style="width: 100%;"
							value="#{newsController.element.newsType.id}" required="true">
							<f:selectItems value="#{propertiesHandler.tipoInformazioneItems}" />
						</h:selectOneMenu>

						<h:outputLabel for="autore" value="Autore:" style="width: 100%;" />
						<h:inputText id="autore" value="#{newsController.element.author}"
							style="width: 100%;" required="true" />


						<h:outputLabel for="anteprima" value="Anteprima:" />
						<h:inputTextarea id="anteprima" cols="20" rows="20"
							value="#{newsController.element.preview}"
							style=" height : 166px; width: 100%;" />


						<h:outputLabel for="descrizione" value="Contenuto:" />
						<p:editor id="descrizione"
							value="#{newsController.element.content}" width="100%"
							height="320px" widgetVar="myEditor" language="it" />

					</h:panelGrid>
					<br />
				</p:panel>
				<br /> <br />
				<h:panelGrid columns="4">

					<h:commandButton action="#{newsController.save}" value="Salva"
						immediate="false" rendered="#{not newsController.editMode}" />

					<h:commandButton action="#{newsController.update}"
						value="Salva le modifiche" immediate="false"
						rendered="#{newsController.editMode}" />

					<h:commandButton action="#{newsController.delete}" value="Elimina"
						rendered="#{newsController.editMode}" immediate="true"
						onclick="if (!confirm('Vuoi davvero eliminare?')) return false" />
				</h:panelGrid>
			</center>
		</h:form>

	</ui:define>
</ui:composition>